
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class ThemeTestRoute extends StatefulWidget {
  @override
  _ThemeTestRouteState createState() => _ThemeTestRouteState();
}

class _ThemeTestRouteState extends State<ThemeTestRoute> {
  var _themeColor = Colors.teal; //当前路由主题色
  var _systemUiOverlayStyle = SystemUiOverlayStyle.dark; //当前路由主题色
  var _switch = false; //当前路由主题色

  @override
  Widget build(BuildContext context) {
    ThemeData themeData = Theme.of(context);
    return Theme(
      data: ThemeData(
          primarySwatch: _themeColor, //用于导航栏、FloatingActionButton的背景色等
          iconTheme: IconThemeData(color: _themeColor) //用于Icon颜色
      ),
      child: Scaffold(
        // appBar: AppBar(title: const Text("主题测试"),
        //   // backgroundColor: Colors.white, // 控制状态栏颜色
        //   // foregroundColor: Colors.black, // 设置文字/图标颜色
        //   // systemOverlayStyle: _systemUiOverlayStyle,  //状态栏字体样式
        // ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            //第一行Icon使用主题中的iconTheme
           const Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Icon(Icons.favorite),
                  Icon(Icons.airport_shuttle),
                  Text("  颜色跟随主题")
                ]
            ),
            //为第二行Icon自定义颜色（固定为黑色)
            Theme(
              data: themeData.copyWith(
                iconTheme: themeData.iconTheme.copyWith(
                    color: Colors.black
                ),
              ),
              child:const Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Icon(Icons.favorite),
                    Icon(Icons.airport_shuttle),
                    Text("  颜色固定黑色")
                  ]
              ),
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: () =>  //切换主题
            setState((){
              // _themeColor =
              // _themeColor == Colors.teal ? Colors.blue : Colors.teal;
              // _systemUiOverlayStyle =
              // _systemUiOverlayStyle == SystemUiOverlayStyle.dark ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark;

              if(_switch){
                SystemChrome.setSystemUIOverlayStyle(
                  const SystemUiOverlayStyle(
                    statusBarColor: Colors.transparent,  //背景颜色
                    // statusBarIconBrightness: Brightness.light,  // Android 白色图标
                    statusBarBrightness: Brightness.light,       // iOS 白色文字
                  ),
                );
              }else{
                SystemChrome.setSystemUIOverlayStyle(
                  const SystemUiOverlayStyle(
                    statusBarColor: Colors.transparent,
                    statusBarIconBrightness: Brightness.dark,  // Android 、黑色图标
                    statusBarBrightness: Brightness.dark,       // iOS 白色文字
                  ),
                );
              }
              this._switch = !this._switch;
            }
            ),
            child:const Icon(Icons.palette)
        ),
      ),
    );
  }
}